<?php
declare(strict_types=1);
namespace cms\wechat\admin\mvc_controller;

use cms\wechat\service\AuthorizeService;
use cms\wechat\service\OfficialService;
use cms\wechat\service\PlatformService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Psr\Http\Message\ResponseInterface;

/**
 * Class AuthorizeController
 * @package cms\wechat\admin\mvc_controller
 * @AutoController(prefix="mvc/wechat/admin_authorize")
 */
class AuthorizeController extends CommonController
{
    /**
     * @Inject()
     * @var PlatformService
     */
    protected PlatformService $platformService;

    /**
     * @Inject()
     * @var OfficialService
     */
    protected OfficialService $officialService;

    /**
     * @Inject()
     * @var AuthorizeService
     */
    protected AuthorizeService $authorizeService;

    /**
     * @return ResponseInterface
     */
    public function retrieve(): ResponseInterface
    {
        $platform_id = (int) $this->request->input('platform_id', 0);
        $platform = $this->platformService->getDataById($platform_id);
        $official_id = (int) $this->request->input('official_id', 0);
        $official = $this->officialService->getDataById($official_id);
        return $this->template([
            'platform' => $platform,
            'official' => $official,
        ]);
    }

    /**
     * @return ResponseInterface
     */
    public function detail(): ResponseInterface
    {
        $id = (int) $this->request->input('id', 0);
        $data = $this->authorizeService->getDataById($id, true);
        return $this->template([
            'data' => $data
        ]);
    }
}